<?php
namespace App\Http\Controllers\Front;

use App\Service\Front\YewuService;
use Illuminate\Http\Request;

class YewuController extends BaseController
{
    //业务

    //列表
    public function getIndex(Request $request)
    {
        header("Access-Control-Allow-Origin: *");
        $type = $request->get('type', 0); //业务类型
        $pages['start'] = $request->get('page', 1);
        $pages['limit'] = $request->get('limit', 10);
        if (!$type) {
            return $this->toJson(-2, '业务类型必须的');
        }
        $res = (new YewuService())->getIndex($type, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //添加
    public function add(Request $request)
    {
        header("Access-Control-Allow-Origin: *");
        $pas = $request->all();
        $type = isset($pas['type']) ? $pas['type'] : ''; //业务类型
        if (!$type) {
            return $this->toJson(-2, '业务类型必须的');
        }
        unset($pas['token']); unset($pas['s']);
        unset($pas['id']); unset($pas['type']);
        $res = (new YewuService())->add($type, $pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}